import time
from Common.Utils import WebDriver
from Test.Login import login
from selenium.webdriver.common.by import By


class Person:
    url = ""
    driver = ""

    def __init__(self):
        self.url = "http://localhost:8080/#/login?redirect=%2Fdashboard"
        self.driver = WebDriver.driver
        self.driver.get(self.url)
        self.driver.implicitly_wait(3)

    # 登录工作
    def Login(self, user, password):
        login.Init(user, password)
        login.autoIdentifyCode()
        time.sleep(7)
        self.driver.find_element(By.CSS_SELECTOR, "#app > div > form > button").click()

    # 更改用户名
    def ChangeUser(self):
        self.Login('admin', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()

        self.driver.find_element(By.CSS_SELECTOR, '#pane-account > ul > li:nth-child(2) > p.desc > a').click()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div.el-form-item.is-success.is-required > div > div > input').send_keys(
            'root')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person1.png')

        self.Login('root', 'admin')
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person2.png')

        self.Login('root', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person3.png')

    # 更改邮箱
    def ChangeEmail(self):
        self.driver.find_element(By.CSS_SELECTOR, '#pane-account > ul > li:nth-child(2) > p.desc > a').click()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div.el-form-item.is-success.is-required > div > div > input').clear()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div.el-form-item.is-success.is-required > div > div > input').send_keys(
            'a@qq.com')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person4.png')

        self.Login('root', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person5.png')

    # 更改手机号
    def ChangePhone(self):
        self.driver.find_element(By.CSS_SELECTOR, '#pane-account > ul > li:nth-child(2) > p.desc > a').click()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div:nth-child(4) > div > div > input').clear()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div:nth-child(4) > div > div > input').send_keys(
            '13800000000')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person6.png')

        self.Login('root', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person7.png')

    # 更改地址
    def ChangeAddress(self):
        self.driver.find_element(By.CSS_SELECTOR, '#pane-account > ul > li:nth-child(2) > p.desc > a').click()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div:nth-child(5) > div > div > input').clear()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__body > form > div:nth-child(5) > div > div > input').send_keys(
            '冰岛')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person8.png')

        self.Login('root', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person9.png')

    # 更改密码，输入错误的原密码
    def ChangePasswordFail1(self):
        self.driver.find_element(By.CSS_SELECTOR, '#pane-account > ul > li:nth-child(1) > p.desc > a').click()
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(1) > div > div > input').send_keys(
            'aaaaa')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '<input type="password" autocomplete="off" placeholder="请输入新密码" class="el-input__inner">').send_keys(
            'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(3) > div > div.el-input > input').send_keys(
            'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person10.png')

    # 更改密码，确认密码与新密码不同
    def ChangePasswordFail2(self):
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__footer > div > button.el-button.el-button--default > span').click()

        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(1) > div > div > input').send_keys(
            'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '<input type="password" autocomplete="off" placeholder="请输入新密码" class="el-input__inner">').send_keys(
            'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(3) > div > div.el-input > input').send_keys(
            'admin2')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person11.png')

    # 正确修改密码
    def ChangePasswordSuc(self):
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__footer > div > button.el-button.el-button--default > span').click()

        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(1) > div > div > input').send_keys(
            'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '<input type="password" autocomplete="off" placeholder="请输入新密码" class="el-input__inner">').send_keys(
            'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(2) > div > div.el-dialog__body > form > div:nth-child(3) > div > div.el-input > input').send_keys(
            'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.main-container > section > div > div:nth-child(3) > div > div.el-dialog__footer > div > button.el-button.el-button--primary > span').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person12.png')

        self.Login('root', 'admin')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person13.png')

        self.Login('root', 'admin1')
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#app > div > div.sidebar-container.has-logo > div.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(7) > a > li').click()
        time.sleep(0.5)
        self.driver.save_screenshot('../images/person/person14.png')


person = Person()
person.ChangeUser()
person.ChangeEmail()
person.ChangePhone()
person.ChangeAddress()
person.ChangePasswordFail1()
person.ChangePasswordFail2()
person.ChangePasswordSuc()
